package com.fenghongzhang.day009;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;


/**
 * A simple {@link Fragment} subclass.
 */
public class BlankFragment extends Fragment {
    private Button btn;

    //1, 声明一个你的Activity的对象.
    private Main2Activity main2Activity;

    //2, 给你Activity对象赋值
    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        main2Activity = (Main2Activity) getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        View inflate = inflater.inflate(R.layout.fragment_blank, container, false);
        btn = (Button) inflate.findViewById(R.id.btn);

        //3,点击跳转的时间.
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //这个方法,是你Activity中的方法.方法名称自己可以随意定义.
                main2Activity.senPage(1);
            }
        });

        return inflate;
    }
}
